import { ADD_COUNT, ADD_PRODUCT } from './mutition_type'


export default {
  addCart(context, payload) {

    // state.cartlist.push(payload)
    // let oldproduct = null;
    // for (let item of state.cartlist) {
    //   if (item.iid === payload.iid) {
    //     oldproduct = item;
    //   }
    // }

    const oldproduct = context.state.cartlist.find(item => payload.iid === item.iid)

    if (oldproduct) {
      context.commit(ADD_COUNT, oldproduct)

    } else {
      payload.counter = 1
      context.commit(ADD_PRODUCT, payload)

    }
  }
}